<template>
  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-button type="primary" @click="toPublishArticle">发布疫情资讯</el-button>
    </div>
    <!-- / 按钮结束 -->
    <!-- 表格 -->
    <el-table :data="articles.list">
      <el-table-column label="标题" prop="title"></el-table-column>
      <el-table-column label="发布时间" prop="publishTime"></el-table-column>
      <el-table-column label="阅读次数" prop="readTimes"></el-table-column>
      <el-table-column label="所属分类" prop="category.name"></el-table-column>
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="toDelete(scope.row)">删除</el-button>
          <el-button size="mini" type="primary" @click="toEdit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      layout="prev, pager, next"
      @current-change="currentChange"
      :current-page="articles.page"
      :page-size="articles.pageSize"
      :total="articles.total">
    </el-pagination>

    <!-- /分页组件 -->
  </div>
</template>
<script>
import {get} from '@/utils/request'
export default {
  data(){
    return {
      articles:{ list:[] },
      param:{
        page:1,
        pageSize:10
      }
    }
  },
  mounted(){
    this.loadArticles();
  },
  methods:{
    // 当前页发生变化
    currentChange(page){
      this.param.page = page;
      this.loadArticles();
    },
    // 去编辑
    toEdit(row){
      // 跳转到资讯发布页面
      this.$router.push({
        path:'/cms/article_create',
        query:row     // 携带参数
      })
    },
    // 去删除
    toDelete(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let url = "http://121.199.29.84:8002/article/deleteById"
          get(url,{id:row.id}).then(resp => {
            // 提示删除成功
            this.$message({type:"success",message:resp.message})
            // 加载文章数据
            this.loadArticles();
          })
        })
    },
    // 去发布资讯
    toPublishArticle(){
      // 跳转到资讯发布页面
      this.$router.push({
        path:'/cms/article_create'
      })
    },
    loadArticles(){
      let url = "http://121.199.29.84:8002/article/pageQuery";
      get(url,this.param).then(resp => {
        this.articles = resp.data;
      })
    }
  }
}
</script>
<style scoped>

</style>